package com.photoeditor.demo.ui.widget;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Interpolator;

import androidx.annotation.Keep;

public class RippleDetector implements Callback {
    private Handler A = new Handler(this);
    private Runnable B = new Runnable() {
        public void run() {
            if (RippleDetector.this.w) {
                RippleDetector.this.f13118o = 0.0f;
                RippleDetector.this.f13122v = true;
                RippleDetector.this.e();
                RippleDetector.this.w = false;
                return;
            }
            RippleDetector.this.s.start();
        }
    };
    private AnimatorListener C = new AnimatorListener() {
        public void onAnimationCancel(Animator animator) {
        }

        public void onAnimationRepeat(Animator animator) {
        }

        public void onAnimationStart(Animator animator) {
            RippleDetector rippleDetector = RippleDetector.this;
            rippleDetector.f13113c = true;
            rippleDetector.f13122v = true;
        }

        public void onAnimationEnd(Animator animator) {
            RippleDetector rippleDetector = RippleDetector.this;
            rippleDetector.f13114d = false;
            rippleDetector.f13113c = false;
            rippleDetector.f13111a.postInvalidate();
            RippleDetector.this.w = false;
        }
    };
    private Interpolator D = new AccelerateDecelerateInterpolator();

    /* renamed from: a reason: collision with root package name */
    View f13111a;

    /* renamed from: b reason: collision with root package name */
    a f13112b;

    /* renamed from: c reason: collision with root package name */
    boolean f13113c;

    /* renamed from: d reason: collision with root package name */
    boolean f13114d;

    /* renamed from: e reason: collision with root package name */
    private int f13115e;
    private Paint f;
    private int g;
    private int h;
    private int i = 1000;
    private float j;
    private float k;

    /* renamed from: l reason: collision with root package name */
    private float f13116l;
    private float m;

    /* renamed from: n reason: collision with root package name */
    private float f13117n;
    /* access modifiers changed from: private */

    /* renamed from: o reason: collision with root package name */
    public float f13118o;

    /* renamed from: p reason: collision with root package name */
    private int f13119p;

    /* renamed from: q reason: collision with root package name */
    private int f13120q;
    private int r;
    /* access modifiers changed from: private */
    public ObjectAnimator s;
    private ObjectAnimator t;

    /* renamed from: u reason: collision with root package name */
    private boolean f13121u;
    /* access modifiers changed from: private */

    /* renamed from: v reason: collision with root package name */
    public boolean f13122v;
    /* access modifiers changed from: private */
    public boolean w = false;

    /* renamed from: x reason: collision with root package name */
    private boolean f13123x;
    /* access modifiers changed from: private */
    public boolean y;
    /* access modifiers changed from: private */
    public boolean z;

    public interface a {
        void a(View view);

        void b(View view);
    }

    public void a(boolean z2) {
        this.f13123x = z2;
    }

    public RippleDetector(Context context, View view, a aVar, int i2) {
        this.f13111a = view;
        this.f13112b = aVar;
        b(i2);
        this.r = ViewConfiguration.get(context).getScaledEdgeSlop();
    }

    public void a() {
        ObjectAnimator objectAnimator = this.t;
        if (objectAnimator != null) {
            objectAnimator.resume();
        }
        ObjectAnimator objectAnimator2 = this.s;
        if (objectAnimator2 != null) {
            objectAnimator2.resume();
        }
    }

    public void b() {
        ObjectAnimator objectAnimator = this.s;
        if (objectAnimator != null) {
            objectAnimator.pause();
        }
        ObjectAnimator objectAnimator2 = this.t;
        if (objectAnimator2 != null) {
            objectAnimator2.pause();
        }
    }

    private void b(int i2) {
        if (this.f13115e != i2) {
            Log.d("Material", "ColorChanged");
            this.f13115e = i2;
            setAlpha(25);
        }
    }

    private void f() {
        if (this.f == null) {
            this.f = new Paint();
        }
        this.f.setColor(this.h);
    }

    private int b(int i2, int i3) {
        return Color.argb(i3, Color.red(i2), Color.green(i2), Color.blue(i2));
    }

    private int c(int i2, int i3) {
        return Color.argb(i3, Color.red(i2), Color.green(i2), Color.blue(i2));
    }

    public void a(int i2, int i3) {
        this.f13119p = i2;
        this.f13120q = i3;
        int i4 = this.f13119p;
        int i5 = (i4 * i4) / 4;
        int i6 = this.f13120q;
        this.f13117n = (float) Math.sqrt((double) (i5 + ((i6 * i6) / 4)));
        if (this.t != null) {
            d();
            c();
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:8:0x0020, code lost:
        if (r1.isRunning() != false) goto L_0x0022;
     */
    /* JADX WARNING: Removed duplicated region for block: B:14:0x008e  */
    /* JADX WARNING: Removed duplicated region for block: B:21:? A[RETURN, SYNTHETIC] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public boolean a(MotionEvent r6, boolean r7) {
        switch (r6.getAction()) {
            case MotionEvent.ACTION_CANCEL:
                A.removeCallbacks(B);
            case MotionEvent.ACTION_UP:
                w = true;
                if (f13123x) {
                    e();
                    c();
                }
                g();
                return true;
            case MotionEvent.ACTION_DOWN:
                f13121u = true;
                w = false;
                f13122v = false;
                if (f13113c) {
                    if (t == null|| !t.isRunning()) {
                        return true;
                    }
                }
                d();
                j = r6.getX();
                k = r6.getY();
                f13116l = r6.getX();
                m = r6.getY();
                if (s == null) {
                    float[] v = new float[2];
                    v[0] = r;
                    v[1] = f13117n;
                    s = ObjectAnimator.ofFloat(this, "radius", v);
                    s.setDuration(i);
                    s.setInterpolator(D);
                    s.addListener(C);
                }
                A.postDelayed(B, 100);
                return true;
                default:
                    return true;
        }
        /*
            r5 = this;
            int r0 = r6.getAction()
            r1 = 3
            r2 = 1
            if (r0 == r1) goto L_0x0090
            switch(r0) {
                case 0: goto L_0x000d;
                case 1: goto L_0x0097;
                default: goto L_0x000b;
            }
        L_0x000b:
            goto L_0x00a7
        L_0x000d:
            r5.f13121u = r2
            r0 = 0
            r5.w = r0
            r5.f13122v = r0
            boolean r1 = r5.f13113c
            if (r1 == 0) goto L_0x0022
            android.animation.ObjectAnimator r1 = r5.t
            if (r1 == 0) goto L_0x008c
            boolean r1 = r1.isRunning()
            if (r1 == 0) goto L_0x008c
        L_0x0022:
            r5.d()
            float r1 = r6.getX()
            r5.j = r1
            float r1 = r6.getY()
            r5.k = r1
            float r1 = r6.getX()
            r5.f13116l = r1
            float r6 = r6.getY()
            r5.m = r6
            android.animation.ObjectAnimator r6 = r5.s
            if (r6 != 0) goto L_0x006b
            java.lang.String r6 = "radius"
            r1 = 2
            float[] r1 = new float[r1]
            int r3 = r5.r
            float r3 = (float) r3
            r1[r0] = r3
            float r0 = r5.f13117n
            r1[r2] = r0
            android.animation.ObjectAnimator r6 = android.animation.ObjectAnimator.ofFloat(r5, r6, r1)
            r5.s = r6
            int r6 = r5.i
            android.animation.ObjectAnimator r0 = r5.s
            long r3 = (long) r6
            r0.setDuration(r3)
            android.animation.ObjectAnimator r6 = r5.s
            android.view.animation.Interpolator r0 = r5.D
            r6.setInterpolator(r0)
            android.animation.ObjectAnimator r6 = r5.s
            android.animation.Animator$AnimatorListener r0 = r5.C
            r6.addListener(r0)
        L_0x006b:
            android.os.Handler r6 = r5.A
            java.lang.Runnable r0 = r5.B
            r3 = 100
            r6.postDelayed(r0, r3)
            java.lang.String r6 = "Material"
            java.lang.StringBuilder r0 = new java.lang.StringBuilder
            r0.<init>()
            java.lang.String r1 = "Down,from:0,to:"
            r0.append(r1)
            float r1 = r5.f13117n
            r0.append(r1)
            java.lang.String r0 = r0.toString()
            android.util.Log.e(r6, r0)
        L_0x008c:
            if (r7 != 0) goto L_0x00a7
            r7 = 1
            goto L_0x00a7
        L_0x0090:
            android.os.Handler r6 = r5.A
            java.lang.Runnable r0 = r5.B
            r6.removeCallbacks(r0)
        L_0x0097:
            r5.w = r2
            boolean r6 = r5.f13123x
            if (r6 == 0) goto L_0x00a4
            r5.e()
            r5.c()
            goto L_0x00a7
        L_0x00a4:
            r5.g()
        L_0x00a7:
            return r7
        */
//        throw new UnsupportedOperationException("Method not decompiled: com.horoscope.astrology.zodiac.palmistry.ui.subscribe.RippleDetector.a(android.view.MotionEvent, boolean):boolean");
    }

    public void c() {
        ObjectAnimator objectAnimator = this.s;
        if (objectAnimator == null || !objectAnimator.isRunning()) {
            if (this.t == null) {
                this.t = ObjectAnimator.ofFloat(this, "radius", new float[]{(float) this.r, this.f13117n});
                this.t.setDuration((long) this.i);
                this.t.setInterpolator(this.D);
                this.t.setRepeatCount(-1);
                this.t.addListener(this.C);
            }
            this.f13121u = true;
            this.w = false;
            this.f13122v = false;
            if (i(this.f13111a.getContext())) {
                this.j = (float) a(this.f13111a.getContext(), 30.0f);
                this.k = ((float) this.f13111a.getHeight()) / 2.0f;
                this.f13116l = this.j;
                this.m = this.k;
            } else {
                this.j = (float) (this.f13111a.getWidth() - a(this.f13111a.getContext(), 30.0f));
                this.k = ((float) this.f13111a.getHeight()) / 2.0f;
                this.f13116l = this.j;
                this.m = this.k;
            }
            this.t.start();
        }
    }

    public static boolean i(Context context) {
        return context.getResources().getConfiguration().getLayoutDirection() == 1;
    }

    public int a(Context context, float f) {
        return (int) ((f * context.getResources().getDisplayMetrics().density) + 0.5f);
    }


    public void d() {
        ObjectAnimator objectAnimator = this.t;
        if (objectAnimator != null) {
            objectAnimator.cancel();
            this.t = null;
        }
    }

    private void g() {
        this.f13121u = false;
        if (this.f13122v) {
            e();
            this.j = this.f13116l;
            this.k = this.m;
            this.f13118o = Math.max(this.f13118o, this.f13117n * 0.1f);
            float f2 = this.f13117n;
            float f3 = this.f13118o;
            int i2 = (int) (((f2 - f3) * 600.0f) / f2);
            if (i2 > 0) {
                this.s = ObjectAnimator.ofFloat(this, "radius", new float[]{f3, f2});
                this.s.setDuration((long) i2);
                this.s.setInterpolator(this.D);
                this.s.addListener(this.C);
                this.s.start();
                StringBuilder sb = new StringBuilder();
                sb.append("UP,from:");
                sb.append(this.f13118o);
                sb.append(",to:");
                sb.append(this.f13117n);
                Log.i("Material", sb.toString());
            }
            ObjectAnimator ofInt = ObjectAnimator.ofInt(this, "alpha", new int[]{25, 0});
            ofInt.setDuration(200);
            ofInt.setInterpolator(new AccelerateInterpolator());
            ofInt.addListener(new AnimatorListener() {
                public void onAnimationCancel(Animator animator) {
                }

                public void onAnimationRepeat(Animator animator) {
                }

                public void onAnimationStart(Animator animator) {
                    RippleDetector.this.f13113c = true;
                }

                public void onAnimationEnd(Animator animator) {
                    RippleDetector rippleDetector = RippleDetector.this;
                    rippleDetector.f13114d = false;
                    rippleDetector.f13113c = false;
                    rippleDetector.setAlpha(25);
                    if (RippleDetector.this.y) {
                        if (RippleDetector.this.f13112b != null) {
                            RippleDetector.this.f13112b.a(RippleDetector.this.f13111a);
                        }
                        RippleDetector.this.y = false;
                    }
                    if (RippleDetector.this.z) {
                        if (RippleDetector.this.f13112b != null) {
                            RippleDetector.this.f13112b.b(RippleDetector.this.f13111a);
                        }
                        RippleDetector.this.z = false;
                    }
                }
            });
            ofInt.start();
            this.f13111a.postInvalidate();
        }
    }

    public void e() {
        ObjectAnimator objectAnimator = this.s;
        if (objectAnimator != null) {
            objectAnimator.cancel();
        }
    }

    public void a(Canvas canvas) {
        if (this.f13121u || this.f13113c) {
            Log.d("Material", "DrawFocusColor");
            this.f13114d = true;
            if (this.f13122v) {
                canvas.drawColor(this.g);
            }
            canvas.drawCircle(this.f13116l, this.m, this.f13118o, this.f);
        }
    }

    @Keep
    public void setRadius(float f2) {
        StringBuilder sb = new StringBuilder();
        sb.append("");
        sb.append(f2);
        Log.e("Material", sb.toString());
        ObjectAnimator objectAnimator = this.s;
        float animatedFraction = (objectAnimator == null || !objectAnimator.isRunning()) ? 0.0f : this.s.getAnimatedFraction();
        ObjectAnimator objectAnimator2 = this.t;
        if (objectAnimator2 != null && objectAnimator2.isRunning()) {
            animatedFraction = this.t.getAnimatedFraction();
        }
        this.f13118o = f2;
        float f3 = this.j;
        this.f13116l = ((((float) (this.f13119p / 2)) - f3) * animatedFraction) + f3;
        float f4 = this.k;
        this.m = (animatedFraction * (((float) (this.f13120q / 2)) - f4)) + f4;
        float f5 = this.f13116l;
        float f6 = (f5 - f3) * (f5 - f3);
        float f7 = this.m;
        float sqrt = ((float) Math.sqrt((double) (f6 + ((f7 - f4) * (f7 - f4))))) + ((float) this.r);
        if (sqrt > f2) {
            float f8 = this.j;
            this.f13116l = f8 + (((this.f13116l - f8) * f2) / sqrt);
            float f9 = this.k;
            this.m = f9 + (((this.m - f9) * f2) / sqrt);
        }
        if (!this.A.hasMessages(853)) {
            this.A.sendEmptyMessageDelayed(853, 16);
        }
    }

    @Keep
    public void setAlpha(int i2) {
        this.g = c(this.f13115e, i2);
        this.h = b(this.f13115e, i2);
        f();
        this.f13111a.postInvalidate();
    }

    public void a(int i2) {
        this.i = i2;
    }

    public boolean handleMessage(Message message) {
        if (message.what != 853) {
            return false;
        }
        if (this.f13114d) {
            View view = this.f13111a;
            float f2 = this.f13116l;
            float f3 = this.f13118o;
            int i2 = (int) (f2 - f3);
            float f4 = this.m;
            view.invalidate(i2, (int) (f4 - f3), (int) (f2 + f3), (int) (f4 + f3));
        } else {
            this.f13111a.invalidate();
        }
        return true;
    }
}
